﻿using log4net;
using System;
using System.ComponentModel;
using System.Configuration;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media.Imaging;
using System.Windows.Media;
using System.Windows.Threading;
namespace VirtualWall.Views
{
    /// <summary>
    /// ShellView.xaml 的交互逻辑
    /// </summary>
    public partial class ShellView
    {
        private static readonly ILog log = LogManager.GetLogger("Monitor");

        public ShellView()
        {
            WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
            InitializeComponent();
            Globalspace._Wnd1Handle = RealPlayWnd1.Handle;
            Globalspace._Wnd2Handle = RealPlayWnd2.Handle;
            Globalspace._Wnd3Handle = RealPlayWnd3.Handle;
            Globalspace._Wnd4Handle = RealPlayWnd4.Handle;
        }

        //由于没有标题栏，需要在整个窗口里都可以拖动窗口位置
        private void Window_DragMove(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            try
            {
                this.DragMove();
            }
            catch (Exception ex)
            {
                log.Debug(ex.Message);
            }
        }

        protected override void OnClosing(CancelEventArgs e)
        {
            e.Cancel = true;
            base.OnClosing(e);
        }

        private void Window_Topmost(object sender, RoutedEventArgs e)
        {
           // this.Topmost = true;
        }


        private void CloseButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            try
            {
                //FlowControl.Instance.Dispose();
                Close();
                Application.Current.Shutdown();
            }
            catch (Exception ex)
            {
                log.Debug(ex.Message);
            }

        }
        private void MinButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            this.WindowState = System.Windows.WindowState.Minimized;
        }
        private void MaxButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            var path = "";
            if (this.WindowState == System.Windows.WindowState.Normal)
            {
                path = @"pack://application:,,,/Resources/Img/fd_c.png";
                this.WindowState = System.Windows.WindowState.Maximized;
            }
            else
            {
                this.WindowState = System.Windows.WindowState.Normal;
                path = @"pack://application:,,,/Resources/Img/fd_b.png";
            }
            ImageBrush brush = new ImageBrush();
            var img = new BitmapImage(new Uri(path, UriKind.Absolute));
            brush.ImageSource = img;
            var MaxButton = sender as Button;
            MaxButton.Background = brush;
        }

        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            DragMove();

            base.OnMouseLeftButtonDown(e);
        }

        protected override void OnSourceInitialized(EventArgs e)
        {
            base.OnSourceInitialized(e);
        }

    }
}
